package com.ideaaedi.springcloud.jd.user.controller.sys;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.ideaaedi.springcloud.jd.commonds.entity.PageInfo;
import com.ideaaedi.springcloud.jd.commonds.entity.Result;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDictTypeAddReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDictTypeListReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDictTypeUpdateReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.resp.SysDictTypeDetailRespVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.resp.SysDictTypeListRespVO;
import com.ideaaedi.springcloud.jd.user.service.SysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * 系统 - 数据字典类别
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 *@since 2021.0.1.A
 */
@Slf4j
@Validated
@RestController
@ApiSort(value = 2)
@RequestMapping("/sys-dict-type")
@Api(value = "系统-数据字典类别", tags = {"系统-数据字典类别"})
public class SysDictTypeController {

    @Resource
    private SysDictTypeService sysDictTypeService;

    /**
     * 增
     *
     * @param req 参数
     *
     * @return 新增的数据详情
     */
    @PostMapping("/add")
    @ApiOperation(value = "增")
    @ApiOperationSupport(order = 1)
    public Result<SysDictTypeDetailRespVO> add(@RequestBody @Validated SysDictTypeAddReqVO req) {
        return Result.success(sysDictTypeService.add(req));
    }

    /**
     * 删
     *
     * @param id 要删除数据的id
     *
     * @return 删除了的数据详情
     */
    @ApiOperation(value = "删")
    @ApiOperationSupport(order = 2)
    @DeleteMapping("/delete/{id}")
    public Result<SysDictTypeDetailRespVO> delete(@ApiParam(value = "要删除数据的id", required = true)
                                                  @PathVariable("id") @NotNull(message = "id cannot be null.") Integer id) {
        return Result.success(sysDictTypeService.delete(id));
    }

    /**
     * 改
     *
     * @param req 参数
     *
     * @return 修改后的数据详情
     */
    @PutMapping("/update")
    @ApiOperation(value = "改")
    @ApiOperationSupport(order = 3)
    public Result<SysDictTypeDetailRespVO> update(@RequestBody @Validated SysDictTypeUpdateReqVO req) {
        return Result.success(sysDictTypeService.update(req));
    }
    
    /**
     * 查列表
     *
     * @param req 参数
     *
     * @return 数据列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "查列表")
    @ApiOperationSupport(order = 4)
    public Result<PageInfo<SysDictTypeListRespVO>> list(@RequestBody @Validated SysDictTypeListReqVO req) {
        return Result.success(sysDictTypeService.list(req));
    }
    
    /**
     * 查详情
     *
     * @param id 要查询数据的id
     *
     * @return 数据详情
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查详情")
    @ApiOperationSupport(order = 5)
    public Result<SysDictTypeDetailRespVO> detail(@ApiParam(value = "要查询数据的id", required = true)
                                                  @PathVariable("id") @NotNull(message = "id cannot be null.") Integer id) {
        return Result.success(sysDictTypeService.detail(id));
    }
}
